package com.stone.framework.message;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;

import io.swagger.annotations.ApiModelProperty;

public abstract class AbstractMessage<T> implements IMessage<T> {

    private static final long serialVersionUID = -3995532245085370578L;

    @ApiModelProperty(value = "报文体", required = true)
    // @NotNull(message = "[body] {title.notNull}")
    @Valid
    private T body;

    @ApiModelProperty(value = "报文标识", required = true)
    @NotBlank(message = "[uid] {title.notBlank}")
    private String uid;

    /**
     * use for json
     */
    @Deprecated
    public AbstractMessage() {}

    protected AbstractMessage(T body, String uid) {
        this.body = body;
        this.uid = uid;// UUID.randomUUID().toString().replace("-", "");
    }

    @Override
    public T getBody() {
        return body;
    }

    @Override
    public String getUid() {
        return uid;
    }

    /**
     * use for json
     * 
     * @param body
     */
    @Deprecated
    public void setBody(T body) {
        this.body = body;
    }

    /**
     * use for json
     * 
     * @param body
     */
    @Deprecated
    public void setUid(String uid) {
        this.uid = uid;
    }

    @Override
    public String toString() {
        return "[body=" + body + ", uid=" + uid + "]";
    }

}
